package com.zxm.edu.controller;

import com.zxm.edu.annotation.OptLog;
import com.zxm.edu.dto.CourseDTO;
import com.zxm.edu.entity.Course;
import com.zxm.edu.entity.CourseRecord;
import com.zxm.edu.entity.School;
import com.zxm.edu.service.CourseRecordService;
import com.zxm.edu.service.CourseService;
import com.zxm.edu.service.UserInfoService;
import com.zxm.edu.vo.ConditionVO;
import com.zxm.edu.vo.CourseVO;
import com.zxm.edu.vo.PageResult;
import com.zxm.edu.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

import static com.zxm.edu.constant.OptTypeConst.REMOVE;
import static com.zxm.edu.constant.OptTypeConst.SAVE_OR_UPDATE;

/**
 * 课程记录控制器
 *
 * @author silencezheng
 * @date 2022/09/04
 */
@Api(tags = "课程购买记录模块")
@RestController
public class CourseRecordController {
    @Autowired
    private CourseRecordService courseRecordService;

    @ApiOperation(value = "查看课程是否已购买")
    @GetMapping("/courseRecord/listCount")
    public Result<?> listCount(Integer courseId) {
        return Result.ok(courseRecordService.listCount(courseId));
    }

    @ApiOperation(value = "查询我的订单")
    @GetMapping("/courseRecord/list")
    public Result<PageResult<CourseRecord>> list(ConditionVO condition) {
        return Result.ok(courseRecordService.list(condition));
    }

    @OptLog(optType = SAVE_OR_UPDATE)
    @ApiOperation(value = "课程支付")
    @PostMapping("/courseRecord/payCourse")
    public Result<?> payCourse(@RequestBody CourseRecord courseRecord) {
        Boolean flag = courseRecordService.payCourse(courseRecord);
        if (!flag){
            return Result.fail("余额不足，支付失败！");
        }
        return Result.ok();
    }
}
